package com.pencilisland.pay.mgt.mp.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import com.pencilisland.pay.api.bean.mp.mgt.MessageRequest;
import com.pencilisland.pay.api.bean.mp.mgt.MessageResponse;

import com.pencilisland.pay.mgt.mp.service.MBService;
import com.pencilisland.pay.mgt.mp.service.MPService;

@Component
public class MPServiceImpl implements MPService {
	Logger logger = LoggerFactory.getLogger(getClass());

	@Autowired
	BeanFactory beanFactory;

	@Override
	public MessageResponse receive(MessageRequest request) {

		if (StringUtils.isEmpty(request.getMessageId())) {
			return new MessageResponse(false,null, "请求报文标识为空");
		}
		// TODO 是否有公共处理

		// MB为message business缩写
		String processBeanName = "MB_" + request.getMessageId();
		if (beanFactory.containsBean(processBeanName)) {
			MBService mbService = beanFactory.getBean(processBeanName,
					MBService.class);
			return mbService.process(request);
		} else {
			return new MessageResponse(false,null, "没有找到报文【{" + request.getMessageId() + "}】处理逻辑");
		}

	}

}
